import com.phidgets.*;
import com.phidgets.event.*;

public class TugOfWarPhidgetSensor extends TugOfWarSensor implements SensorChangeListener, AttachListener {

	private InterfaceKitPhidget ik;

	public TugOfWarPhidgetSensor(RopeState rs) {
		super(rs);	
	}

	public void sensorChanged(SensorChangeEvent se) {
		this.setSensorValue(se.getValue());
	}

	public void attached(AttachEvent ae) {
		System.out.println("attachment of " + ae);
	}

	public void initialize() {
		try {
			ik = new InterfaceKitPhidget();
			ik.addAttachListener(this);
			ik.addSensorChangeListener(this);
			ik.openAny();	
			System.out.println("waiting for IK attachment...");
			ik.waitForAttachment();
			System.out.println("IK information: " + ik.getSerialNumber());
		} catch (Exception e) {
			//System.out.println(e);
			e.printStackTrace();
			System.out.println("Fatal error: Failed to initialize sensor.");
			System.exit(1);		
		}
	}

}
